#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unordered_map>

using namespace std;
unordered_map<int,int> m;

int getcount(int n)
{
    int count = 0;
    while (n)
    {
        count += (n % 10) * (n % 10);
        n /= 10;
    }
    return count;
}

bool ishappy(int n)
{
    if (n==0) return false;
    if(n==1)  return true;
    while(true)
    {
        n = getcount(n);
        if (n==1) return true;
        if (n==0) return false;
        if (m[n]==1) return false;
        m[n] = 1;
    }
}

int main()
{
    int a;
    cin>>a;
    if (ishappy(a))
    {
        cout<<"true"<<endl;
    }
    else
    {
        cout<<"false"<<endl;
    }

}